const express = require('express');
const app = express();
const os = require('os');

app.get('/mac-address', (req, res) => {
  //const macAddress = os.networkInterfaces()['eth0'][0].mac;
  var macAddress = getMacAddress();
  res.send(macAddress);
});

const port = process.env.PORT || 3000;
app.listen(port, () => {
  console.log(`Server is running on port ${port}`);
  console.log(`get mac function http get address : http://localhost:3000/mac-address`);
});


function getMacAddress() {
  const networkInterfaces = os.networkInterfaces();
  for (const key in networkInterfaces) {
    const interfaces = networkInterfaces[key];
    for (const i in interfaces) {
      const address = interfaces[i];
      if (address.family === 'IPv4' && !address.internal) {
        return address.mac;
      }
    }
  }
  return null;
}